//
//  MoveCommand.m
//  INFSWA02
//
//  Created by Justin van Grootveld on 10/25/11.
//  Copyright (c) 2011 Pro4all. All rights reserved.
//

#import "MoveCommand.h"
#import "Square.h"
#import "Board.h"

@implementation MoveCommand

- (BOOL)execute
{
    if(!_squareSource || !_squareDestination || ![super board]) return NO;
    
    
    if ([_squareSource isInMoveRangeOfSquareWithPiece:_squareDestination])
    {
        [[super board] movePiece:[_squareSource piece] toSquare:_squareDestination];
        return YES;
    }
    
    return NO;
}

- (BOOL)undo
{
    if(!_squareSource || !_squareDestination || ![super board]) return NO;
    
    [[super board] movePiece:[_squareDestination piece] toSquare:_squareSource];
    
    return YES;
}

@end
